<?php
echo "<pre>";
function upload3()
{
	$files = format();
	$dir = 'upload/'.date('y/m');
	is_dir($dir) or mkdir($dir,0755,true);
	//已经成功上传的文件
	$data=array();
	foreach($files as $f)
	{
		if($f['error']==0 && is_uploaded_file($f['tmp_name']))
		{
			$info = pathinfo($f['name']);
			$dest = $dir.'/'.mt_rand(1,9999).time().'.'.$info['extension'];
			if(move_uploaded_file($f['tmp_name'], $dest))
			{
				$f['time']=time();
				$f['filename']=$dest;
				$data[]=$f;
			}
		}
	}
	return $data;
}

//将不同的上传表单数据统一成一样
function format()
{
	//储存转换后的上传数据
	$files = array();
	foreach($_FILES as $file)
	{
		//表单形式如up[]
		if(is_array($file['name'])){
			foreach($file['name'] as $id=>$name)
			{
				$tmp['name']=$file['name'][$id];
				$tmp['size']=$file['size'][$id];
				$tmp['error']=$file['error'][$id];
				$tmp['tmp_name']=$file['tmp_name'][$id];
				$tmp['type']=$file['type'][$id];
				$files[]=$tmp;
			}
		}else{
			$files[]=$file;
		}
	}
	return $files;
}